package cn.edu.wfit.modules.infomanagement.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;
import cn.edu.wfit.modules.infomanagement.domain.Major;
import cn.edu.wfit.modules.infomanagement.service.IMajorService;
import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.page.TableDataInfo;

/**
 * 专业维护Controller
 * 
 * @author 韩强
 * @date 2024-11-15
 */
@RestController
@RequestMapping("/major")
public class MajorController extends BaseController
{
    @Autowired
    private IMajorService majorService;

    /**
     * 查询专业维护列表
     */
    @RequiresPermissions("system:major:list")
    @GetMapping("/list")
    public TableDataInfo list(Major major)
    {
        startPage();
        List<Major> list = majorService.selectMajorList(major);
        return getDataTable(list);
    }

    /**
     * 导出专业维护列表
     */
    @RequiresPermissions("system:major:export")
    @Log(title = "专业维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Major major)
    {
        List<Major> list = majorService.selectMajorList(major);
        ExcelUtil<Major> util = new ExcelUtil<Major>(Major.class);
        util.exportExcel(response, list, "专业维护数据");
    }

    /**
     * 获取专业维护详细信息
     */
    @RequiresPermissions("system:major:query")
    @GetMapping(value = "/{majorId}")
    public AjaxResult getInfo(@PathVariable("majorId") Long majorId)
    {
        return success(majorService.selectMajorByMajorId(majorId));
    }

    /**
     * 新增专业维护
     */
    @RequiresPermissions("system:major:add")
    @Log(title = "专业维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Major major)
    {
        return toAjax(majorService.insertMajor(major));
    }

    /**
     * 修改专业维护
     */
    @RequiresPermissions("system:major:edit")
    @Log(title = "专业维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Major major)
    {
        return toAjax(majorService.updateMajor(major));
    }

    /**
     * 删除专业维护
     */
    @RequiresPermissions("system:major:remove")
    @Log(title = "专业维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{majorIds}")
    public AjaxResult remove(@PathVariable Long[] majorIds)
    {
        return toAjax(majorService.deleteMajorByMajorIds(majorIds));
    }
}
